```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring Bean 生命周期详解 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .code-block {
            background-color: #2d2d2d;
            border-radius: 8px;
            position: relative;
        }
        .code-header {
            background-color: #1e1e1e;
            border-top-left-radius: 8px;
            border-top-right-radius: 8px;
            padding: 8px 12px;
            color: #9e9e9e;
            font-family: 'Courier New', Courier, monospace;
            font-size: 0.9rem;
        }
        pre {
            margin: 0;
            padding: 16px;
            overflow-x: auto;
            color: #f8f8f2;
            font-family: 'Courier New', Courier, monospace;
            line-height: 1.5;
            tab-size: 4;
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
        }
        .lifecycle-card {
            border-left: 4px solid;
        }
        .section-title {
            position: relative;
            padding-left: 1.5rem;
        }
        .section-title:before {
            content: "";
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .highlight {
            background: linear-gradient(120deg, rgba(110,142,251,0.3) 0%, rgba(167,119,227,0.3) 100%);
            background-repeat: no-repeat;
            background-size: 100% 40%;
            background-position: 0 88%;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <header class="hero-gradient text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col items-center text-center">
                <h1 class="text-4xl md:text-5xl font-bold mb-6 font-serif">Spring Bean 生命周期详解</h1>
                <p class="text-xl md:text-2xl max-w-3xl leading-relaxed opacity-90">
                    探索Spring框架中Bean从创建到销毁的全过程
                </p>
                <div class="mt-10 flex space-x-4">
                    <span class="px-4 py-2 bg-white bg-opacity-20 rounded-full text-sm font-medium">容器管理</span>
                    <span class="px-4 py-2 bg-white bg-opacity-20 rounded-full text-sm font-medium">依赖注入</span>
                    <span class="px-4 py-2 bg-white bg-opacity-20 rounded-full text-sm font-medium">回调机制</span>
                </div>
            </div>
        </div>
    </header>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-16">
        <!-- Overview Section -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-6 font-serif section-title">1. Spring Bean 生命周期概述</h2>
            <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                <div class="p-8">
                    <p class="text-lg text-gray-700 mb-6">
                        Spring Bean 生命周期是指 Spring 容器从创建一个 Bean 实例到销毁 Bean 实例这一过程中的一系列操作。整个生命周期包含了以下几个关键阶段：
                    </p>
                    <div class="grid md:grid-cols-4 gap-6 mb-8">
                        <div class="bg-indigo-50 p-6 rounded-lg border border-indigo-100 flex flex-col items-center text-center">
                            <div class="w-16 h-16 bg-indigo-100 rounded-full flex items-center justify-center mb-4">
                                <i class="fas fa-birthday-cake text-indigo-600 text-2xl"></i>
                            </div>
                            <h3 class="font-bold text-indigo-800 mb-2">Bean 实例化</h3>
                            <p class="text-gray-600 text-sm">通过反射创建Bean实例</p>
                        </div>
                        <div class="bg-purple-50 p-6 rounded-lg border border-purple-100 flex flex-col items-center text-center">
                            <div class="w-16 h-16 bg-purple-100 rounded-full flex items-center justify-center mb-4">
                                <i class="fas fa-tint text-purple-600 text-2xl"></i>
                            </div>
                            <h3 class="font-bold text-purple-800 mb-2">属性注入</h3>
                            <p class="text-gray-600 text-sm">依赖注入和属性赋值</p>
                        </div>
                        <div class="bg-blue-50 p-6 rounded-lg border border-blue-100 flex flex-col items-center text-center">
                            <div class="w-16 h-16 bg-blue-100 rounded-full flex items-center justify-center mb-4">
                                <i class="fas fa-power-off text-blue-600 text-2xl"></i>
                            </div>
                            <h3 class="font-bold text-blue-800 mb-2">初始化</h3>
                            <p class="text-gray-600 text-sm">回调方法和初始化逻辑</p>
                        </div>
                        <div class="bg-red-50 p-6 rounded-lg border border-red-100 flex flex-col items-center text-center">
                            <div class="w-16 h-16 bg-red-100 rounded-full flex items-center justify-center mb-4">
                                <i class="fas fa-trash-alt text-red-600 text-2xl"></i>
                            </div>
                            <h3 class="font-bold text-red-800 mb-2">销毁</h3>
                            <p class="text-gray-600 text-sm">资源清理和销毁逻辑</p>
                        </div>
                    </div>
                    <p class="text-gray-700">
                        每个阶段中，Spring 提供了钩子方法、回调接口以及容器事件来帮助开发者管理这些过程。
                    </p>
                </div>
            </div>
        </section>

        <!-- Lifecycle Diagram -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-6 font-serif section-title">生命周期流程图</h2>
            <div class="bg-white rounded-xl shadow-md overflow-hidden p-6">
                <div class="mermaid">
                    graph TD
                    A[开始] --> B[Bean实例化]
                    B --> C[属性注入]
                    C --> D[初始化前置处理]
                    D --> E[InitializingBean.afterPropertiesSet]
                    E --> F[@PostConstruct方法]
                    F --> G[自定义init-method]
                    G --> H[Bean就绪可用]
                    H --> I[容器关闭]
                    I --> J[@PreDestroy方法]
                    J --> K[DisposableBean.destroy]
                    K --> L[自定义destroy-method]
                    L --> M[Bean销毁完成]
                </div>
            </div>
        </section>

        <!-- Bean Instantiation -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-6 font-serif section-title">2. Bean 实例化</h2>
            <div class="mb-8">
                <p class="text-lg text-gray-700 mb-6">
                    Spring 容器在启动时会根据配置文件或注解定义的 Bean 来创建实例。<span class="highlight font-medium">`BeanFactory`</span> 是 Spring 的最基本容器，它负责 Bean 的创建。
                </p>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <h3 class="text-xl font-bold mb-4 flex items-center">
                        <i class="fas fa-code-branch text-blue-500 mr-3"></i>
                        2.1. BeanFactory 通过反射创建 Bean
                    </h3>
                    <p class="text-gray-700 mb-4">
                        Spring 使用反射机制来创建 Bean 实例。通常，<code class="bg-gray-100 px-2 py-1 rounded">BeanFactory</code> 实现类（如 <code class="bg-gray-100 px-2 py-1 rounded">DefaultListableBeanFactory</code>）会通过 <code class="bg-gray-100 px-2 py-1 rounded">getBean</code> 方法来查找和创建 Bean。
                    </p>
                    <ul class="space-y-3 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span><code>getBean</code> 方法会查找并创建指定的 Bean</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span><code>createBean</code> 方法通过反射创建 Bean 实例</span>
                        </li>
                    </ul>
                </div>
                <div class="code-block">
                    <div class="code-header flex items-center">
                        <div class="w-3 h-3 rounded-full bg-red-500 mr-2"></div>
                        <div class="w-3 h-3 rounded-full bg-yellow-500 mr-2"></div>
                        <div class="w-3 h-3 rounded-full bg-green-500 mr-3"></div>
                        <span>DefaultListableBeanFactory.java</span>
                    </div>
                    <pre><code class="language-java">public class DefaultListableBeanFactory extends AbstractBeanFactory {

    @Override
    public Object getBean(String name) throws BeansException {
        BeanDefinition beanDefinition = getBeanDefinition(name);
        if (beanDefinition.getBeanClass() == null) {
            // 没有指定类的Bean，使用反射创建
            beanDefinition.setBeanClass(resolveBeanClass(beanDefinition));
        }
        return createBean(beanDefinition);
    }

    protected Object createBean(BeanDefinition beanDefinition) {
        try {
            // 通过反射创建 Bean 实例
            return beanDefinition.getBeanClass().newInstance();
        } catch (Exception e) {
            throw new BeansException("Failed to instantiate bean", e);
        }
    }
}</code></pre>
                </div>
            </div>
        </section>

        <!-- Property Injection -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-6 font-serif section-title">3. 属性注入</h2>
            <div class="mb-8">
                <p class="text-lg text-gray-700 mb-6">
                    在 Spring 的生命周期中，属性注入是紧随 Bean 实例化之后的步骤。Spring 支持多种方式的依赖注入，包括构造器注入、setter 注入和字段注入。
                </p>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <h3 class="text-xl font-bold mb-4 flex items-center">
                        <i class="fas fa-exchange-alt text-purple-500 mr-3"></i>
                        3.1. 依赖注入的执行
                    </h3>
                    <p class="text-gray-700 mb-4">
                        Spring 会根据配置自动注入 Bean 的依赖。<code class="bg-gray-100 px-2 py-1 rounded">AutowireCapableBeanFactory</code> 是负责执行依赖注入的核心接口。
                    </p>
                    <div class="bg-yellow-50 border-l-4 border-yellow-400 p-4 mb-4">
                        <div class="flex">
                            <div class="flex-shrink-0">
                                <i class="fas fa-lightbulb text-yellow-500"></i>
                            </div>
                            <div class="ml-3">
                                <p class="text-sm text-yellow-700">
                                    Spring 支持按类型(<code>AUTOWIRE_BY_TYPE</code>)和按名称(<code>AUTOWIRE_BY_NAME</code>)两种自动注入模式
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="code-block">
                    <div class="code-header flex items-center">
                        <div class="w-3 h-3 rounded-full bg-red-500 mr-2"></div>
                        <div class="w-3 h-3 rounded-full bg-yellow-500 mr-2"></div>
                        <div class="w-3 h-3 rounded-full bg-green-500 mr-3"></div>
                        <span>AutowireCapableBeanFactory.java</span>
                    </div>
                    <pre><code class="language-java">public class AutowireCapableBeanFactory {

    public void autowireBeanProperties(Object existingBean, int autowireMode) {
        // 根据注解或 XML 配置自动注入属性
        if (autowireMode == AUTOWIRE_BY_TYPE) {
            injectByType(existingBean);
        } else if (autowireMode == AUTOWIRE_BY_NAME) {
            injectByName(existingBean);
        }
    }

    private void injectByType(Object existingBean) {
        // 通过类型自动注入属性
    }

    private void injectByName(Object existingBean) {
        // 通过名字自动注入属性
    }
}</code></pre>
                </div>
            </div>
        </section>

        <!-- Initialization Phase -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-6 font-serif section-title">4. 初始化阶段</h2>
            <div class="mb-8">
                <p class="text-lg text-gray-700 mb-6">
                    Bean 实例化并注入属性后，Spring 会调用初始化方法。Spring 提供了多种机制来定制初始化过程。
                </p>
            </div>

            <div class="grid md:grid-cols-3 gap-6 mb-10">
                <!-- @PostConstruct Card -->
                <div class="bg-white rounded-lg shadow-md overflow-hidden lifecycle-card border-l-blue-500 card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-blue-100 flex items-center justify-center mr-4">
                                <i class="fas fa-code text-blue-600"></i>
                            </div>
                            <h3 class="text-lg font-bold">@PostConstruct 注解</h3>
                        </div>
                        <p class="text-gray-600 text-sm mb-4">
                            <code>@PostConstruct</code> 注解用于标注 Bean 初始化方法，该方法会在 Bean 完成属性注入之后、容器完全初始化之前执行。
                        </p>
                        <div class="bg-gray-50 p-3 rounded text-xs font-mono overflow-x-auto">
                            <span class="text-blue-600">@PostConstruct</span><br>
                            <span class="text-purple-600">public void</span> init() {<br>
                            &nbsp;&nbsp;<span class="text-gray-500">// 初始化逻辑</span><br>
                            }
                        </div>
                    </div>
                </div>

                <!-- InitializingBean Card -->
                <div class="bg-white rounded-lg shadow-md overflow-hidden lifecycle-card border-l-purple-500 card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center mr-4">
                                <i class="fas fa-project-diagram text-purple-600"></i>
                            </div>
                            <h3 class="text-lg font-bold">InitializingBean 接口</h3>
                        </div>
                        <p class="text-gray-600 text-sm mb-4">
                            <code>InitializingBean</code> 接口定义了一个 <code>afterPropertiesSet</code> 方法，用于在属性注入完成后执行自定义的初始化逻辑。
                        </p>
                        <div class="bg-gray-50 p-3 rounded text-xs font-mono overflow-x-auto">
                            <span class="text-purple-600">public class</span> MyBean <span class="text-purple-600">implements</span> InitializingBean {<br>
                            &nbsp;&nbsp;<span class="text-purple-600">public void</span> afterPropertiesSet() {<br>
                            &nbsp;&nbsp;&nbsp;&nbsp;<span class="text-gray-500">// 初始化逻辑</span><br>
                            &nbsp;&nbsp;}<br>
                            }
                        </div>
                    </div>
                </div>

                <!-- init-method Card -->
                <div class="bg-white rounded-lg shadow-md overflow-hidden lifecycle-card border-l-green-500 card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-green-100 flex items-center justify-center mr-4">
                                <i class="fas fa-cog text-green-600"></i>
                            </div>
                            <h3 class="text-lg font-bold">init-method 配置</h3>
                        </div>
                        <p class="text-gray-600 text-sm mb-4">
                            在 XML 配置文件中通过 <code>init-method</code> 属性指定一个初始化方法。
                        </p>
                        <div class="bg-gray-50 p-3 rounded text-xs font-mono overflow-x-auto">
                            &lt;<span class="text-red-600">bean</span> <span class="text-blue-600">id=</span><span class="text-green-600">"myBean"</span><br>
                            &nbsp;&nbsp;<span class="text-blue-600">class=</span><span class="text-green-600">"com.example.MyBean"</span><br>
                            &nbsp;&nbsp;<span class="text-blue-600">init-method=</span><span class="text-green-600">"init"</span>&gt;<br>
                            &lt;/<span class="text-red-600">bean</span>&gt;
                        </div>
                    </div>
                </div>
            </div>

            <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                <div class="p-8">
                    <h3 class="text-xl font-bold mb-4">初始化方法执行顺序</h3>
                    <div class="relative">
                        <div class="flex items-start mb-6">
                            <div class="flex items-center justify-center w-10 h-10 rounded-full bg-blue-500 text-white font-bold mr-4 flex-shrink-0">1</div>
                            <div>
                                <h4 class="font-semibold text-gray-800">@PostConstruct 注解方法</h4>
                                <p class="text-gray-600 text-sm">最先执行，在属性注入完成后立即调用</p>
                            </div>
                        </div>
                        <div class="flex items-start mb-6">
                            <div class="flex items-center justify-center w-10 h-10 rounded-full bg-purple-500 text-white font-bold mr-4 flex-shrink-0">2</div>
                            <div>
                                <h4 class="font-semibold text-gray-800">InitializingBean.afterPropertiesSet()</h4>
                                <p class="text-gray-600 text-sm">接着执行，实现接口的初始化方法</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="flex items-center justify-center w-10 h-10 rounded-full bg-green-500 text-white font-bold mr-4 flex-shrink-0">3</div>
                            <div>
                                <h4 class="font-semibold text-gray-800">自定义 init-method</h4>
                                <p class="text-gray-600 text-sm">最后执行，XML配置中指定的初始化方法</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Destruction Phase -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-6 font-serif section-title">5. 销毁阶段</h2>
            <div class="mb-8">
                <p class="text-lg text-gray-700 mb-6">
                    Spring 中的销毁阶段是 Bean 生命周期的最后一步。当容器关闭时，Spring 会调用 Bean 的销毁方法。
                </p>
            </div>

            <div class="grid md:grid-cols-3 gap-6 mb-10">
                <!-- @PreDestroy Card -->
                <div class="bg-white rounded-lg shadow-md overflow-hidden lifecycle-card border-l-red-500 card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-red-100 flex items-center justify-center mr-4">
                                <i class="fas fa-code text-red-600"></i>
                            </div>
                            <h3 class="text-lg font-bold">@PreDestroy 注解</h3>
                        </div>
                        <p class="text-gray-600 text-sm mb-4">
                            <code>@PreDestroy</code> 注解用于标注销毁方法，在 Bean 销毁之前执行。
                        </p>
                        <div class="bg-gray-50 p-3 rounded text-xs font-mono overflow-x-auto">
                            <span class="text-red-600">@PreDestroy</span><br>
                            <span class="text-purple-600">public void</span> destroy() {<br>
                            &nbsp;&nbsp;<span class="text-gray-500">// 销毁逻辑</span><br>
                            }
                        </div>
                    </div>
                </div>

                <!-- DisposableBean Card -->
                <div class="bg-white rounded-lg shadow-md overflow-hidden lifecycle-card border-l-orange-500 card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-orange-100 flex items-center justify-center mr-4">
                                <i class="fas fa-project-diagram text-orange-600"></i>
                            </div>
                            <h3 class="text-lg font-bold">DisposableBean 接口</h3>
                        </div>
                        <p class="text-gray-600 text-sm mb-4">
                            <code>DisposableBean</code> 接口定义了 <code>destroy</code> 方法，当容器销毁 Bean 时，该方法会被调用。
                        </p>
                        <div class="bg-gray-50 p-3 rounded text-xs font-mono overflow-x-auto">
                            <span class="text-purple-600">public class</span> MyBean <span class="text-purple-600">implements</span> DisposableBean {<br>
                            &nbsp;&nbsp;<span class="text-purple-600">public void</span> destroy() {<br>
                            &nbsp;&nbsp;&nbsp;&nbsp;<span class="text-gray-500">// 销毁逻辑</span><br>
                            &nbsp;&nbsp;}<br>
                            }
                        </div>
                    </div>
                </div>

                <!-- destroy-method Card -->
                <div class="bg-white rounded-lg shadow-md overflow-hidden lifecycle-card border-l-yellow-500 card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-yellow-100 flex items-center justify-center mr-4">
                                <i class="fas fa-cog text-yellow-600"></i>
                            </div>
                            <h3 class="text-lg font-bold">destroy-method 配置</h3>
                        </div>
                        <p class="text-gray-600 text-sm mb-4">
                            在 XML 配置文件中，可以通过 <code>destroy-method</code> 属性指定销毁方法。
                        </p>
                        <div class="bg-gray-50 p-3 rounded text-xs font-mono overflow-x-auto">
                            &lt;<span class="text-red-600">bean</span> <span class="text-blue-600">id=</span><span class="text-green-600">"myBean"</span><br>
                            &nbsp;&nbsp;<span class="text-blue-600">class=</span><span class="text-green-600">"com.example.MyBean"</span><br>
                            &nbsp;&nbsp;<span class="text-blue-600">destroy-method=</span><span class="text-green-600">"destroy"</span>&gt;<br>
                            &lt;/<span class="text-red-600">bean</span>&gt;
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Lifecycle Flow -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-6 font-serif section-title">6. Spring Bean 生命周期的执行流程</h2>
            <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                <div class="p-8">
                    <p class="text-lg text-gray-700 mb-6">
                        整个 Bean 的生命周期包括实例化、属性注入、初始化和销毁，每个阶段会触发不同的回调接口和注解，开发者可以在这些阶段插入自定义的业务逻辑。
                    </p>
                    
                    <h3 class="text-xl font-bold mb-4">6.1. 执行流程</h3>
                    <div class="relative">
                        <!-- Timeline -->
                        <div class="border-l-4 border-blue-200 ml-4 pl-8 space-y-10">
                            <!-- Step 1 -->
                            <div class="relative">
                                <div class="absolute -left-14 top-0 w-10 h-10 rounded-full bg-blue-500 text-white flex items-center justify-center shadow-lg">
                                    <span class="font-bold">1</span>
                                </div>
                                <div class="pl-4">
                                    <h4 class="font-semibold text-lg text-gray-800 mb-2">实例化</h4>
                                    <p class="text-gray-600">通过反射创建 Bean 实例</p>
                                </div>
                            </div>
                            
                            <!-- Step 2 -->
                            <div class="relative">
                                <div class="absolute -left-14 top-0 w-10 h-10 rounded-full bg-purple-500 text-white flex items-center justify-center shadow-lg">
                                    <span class="font-bold">2</span>
                                </div>
                                <div class="pl-4">
                                    <h4 class="font-semibold text-lg text-gray-800 mb-2">属性注入</h4>
                                    <p class="text-gray-600">通过 <code>AutowireCapableBeanFactory</code> 实现自动注入</p>
                                </div>
                            </div>
                            
                            <!-- Step 3 -->
                            <div class="relative">
                                <div class="absolute -left-14 top-0 w-10 h-10 rounded-full bg-green-500 text-white flex items-center justify-center shadow-lg">
                                    <span class="font-bold">3</span>
                                </div>
                                <div class="pl-4">
                                    <h4 class="font-semibold text-lg text-gray-800 mb-2">初始化</h4>
                                    <div class="space-y-2">
                                        <div class="flex items-start">
                                            <i class="fas fa-arrow-right text-xs text-gray-400 mt-1.5 mr-2"></i>
                                            <p class="text-gray-600">如果有 <code>@PostConstruct</code> 注解，则调用相应的方法</p>
                                        </div>
                                        <div class="flex items-start">
                                            <i class="fas fa-arrow-right text-xs text-gray-400 mt-1.5 mr-2"></i>
                                            <p class="text-gray-600">如果实现了 <code>InitializingBean</code>，则调用 <code>afterPropertiesSet</code></p>
                                        </div>
                                        <div class="flex items-start">
                                            <i class="fas fa-arrow-right text-xs text-gray-400 mt-1.5 mr-2"></i>
                                            <p class="text-gray-600">如果在 XML 配置文件中定义了 <code>init-method</code>，则调用该方法</p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            
                            <!-- Step 4 -->
                            <div class="relative">
                                <div class="absolute -left-14 top-0 w-10 h-10 rounded-full bg-red-500 text-white flex items-center justify-center shadow-lg">
                                    <span class="font-bold">4</span>
                                </div>
                                <div class="pl-4">
                                    <h4 class="font-semibold text-lg text-gray-800 mb-2">销毁</h4>
                                    <div class="space-y-2">
                                        <div class="flex items-start">
                                            <i class="fas fa-arrow-right text-xs text-gray-400 mt-1.5 mr-2"></i>
                                            <p class="text-gray-600">如果有 <code>@PreDestroy</code> 注解，则调用相应的方法</p>
                                        </div>
                                        <div class="flex items-start">
                                            <i class="fas fa-arrow-right text-xs text-gray-400 mt-1.5 mr-2"></i>
                                            <p class="text-gray-600">如果实现了 <code>DisposableBean</code> 接口，则调用 <code>destroy</code></p>
                                        </div>
                                        <div class="flex items-start">
                                            <i class="fas fa-arrow-right text-xs text-gray-400 mt-1.5 mr-2"></i>
                                            <p class="text-gray-600">如果在 XML 配置文件中定义了 <code>destroy-method</code>，则调用该方法</p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Extension Mechanism -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-6 font-serif section-title">7. 生命周期管理的扩展机制</h2>
            <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                <div class="p-8">
                    <p class="text-lg text-gray-700 mb-6">
                        Spring 的生命周期管理非常灵活，可以通过多种方式扩展生命周期的管理，例如使用 AOP 进行生命周期增强、使用事件监听来响应生命周期的不同阶段等。
                    </p>
                    
                    <h3 class="text-xl font-bold mb-4 flex items-center">
                        <i class="fas fa-expand-arrows-alt text-indigo-500 mr-3"></i>
                        7.1. 通过 AOP 增强生命周期
                    </h3>
                    <p class="text-gray-700 mb-6">
                        Spring 提供了基于 AOP 的生命周期增强机制，可以在 Bean 的生命周期中插入自定义逻辑。
                    </p>
                    
                    <div class="grid md:grid-cols-2 gap-8">
                        <div>
                            <h4 class="font-semibold text-gray-800 mb-3">AOP 生命周期切面示例</h4>
                            <ul class="space-y-3 text-gray-700">
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>在初始化之前执行自定义逻辑</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>在销毁之后执行自定义逻辑</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span>可以应用于所有 Bean 或特定 Bean</span>
                                </li>
                            </ul>
                        </div>
                        <div class="code-block">
                            <div class="code-header flex items-center">
                                <div class="w-3 h-3 rounded-full bg-red-500 mr-2"></div>
                                <div class="w-3 h-3 rounded-full bg-yellow-500 mr-2"></div>
                                <div class="w-3 h-3 rounded-full bg-green-500 mr-3"></div>
                                <span>LifecycleAspect.java</span>
                            </div>
                            <pre><code class="language-java">@Aspect
public class LifecycleAspect {

    @Before("execution(* com.example.MyBean.init(..))")
    public void beforeInit() {
        // 在初始化之前执行逻辑
    }

    @After("execution(* com.example.MyBean.destroy(..))")
    public void afterDestroy() {
        // 在销毁之后执行逻辑
    }
}</code></pre>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-white py-12">
        <div class="container mx-auto px-4">
            <div class="flex flex-col items-center">
                <div class="mb-4">
                    <h3 class="text-xl font-bold">技术小馆</h3>
                </div>
                <div class="mb-6">
                    <a href="http://www.yuque.com/jtostring" class="text-gray-300 hover:text-white transition-colors duration-300">
                        <i class="fas fa-link mr-2"></i>http://www.yuque.com/jtostring
                    </a>
                </div>
                <div class="text-gray-400 text-sm">
                    &copy; 2023 技术小馆. 保留所有权利.
                </div>
            </div>
        </div>
    </footer>

    <script>
        // Initialize Mermaid
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```